package core2.ch02xml;

import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.File;

//import xmlwriter.XMLProperties; 
public class XmlParser2 {
	public static void main(String args[]) {
		try {
			File file = new File("src\\parse\\xml\\XmlParser2.xml");
			System.out.println(file.getAbsolutePath());
			DocumentBuilderFactory factory = DocumentBuilderFactory
					.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			Document doc = builder.parse(file);
			doc.normalize();
			Element theRoot = doc.getDocumentElement();

			NodeList theList = theRoot.getChildNodes();
			System.out.println("the students root has " + theList.getLength()
					+ " children");
			//RecurDOM(theList);
			
			System.out.println(theRoot.getElementsByTagName("first-name").item(0).getTextContent());
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

//	public static void RecurDOM(NodeList nodelist) {
//		Node node;
//		int i;
//		if (nodelist.getLength() == 0) {
//			System.out.println(nodelist.item(0).getNodeValue());
//			//System.out.println(nodelist.getElementsByTagName("first-name").item(0).getTextContent());
//			return;
//		}
//		for (i = 0; i < nodelist.getLength(); i++) {
//			node = nodelist.item(i);
//			if (node.getNodeType() == Node.ELEMENT_NODE)
//				RecurDOM(node.getChildNodes());
//		}
//	}
}
